#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/10/6 13:11
# @Author  : AshJo
# @Desc    : 多进程模拟socketserver-服务端
# @Filename: server.py
# @Version : v1.0
"""

import socket
from multiprocessing import Process


def talk(conn):
    while True:
        msg = conn.recv(1024).decode('utf-8')
        ret = msg.upper().encode('utf-8')
        conn.send(ret)
    conn.close()


if __name__ == '__main__':
    sk = socket.socket()
    sk.bind(('127.0.0.1', 9000))
    sk.listen()
    while True:
        conn, addr = sk.accept()
        Process(target=talk, args=(conn,)).start()
    sk.close()
